package com.ruoyi.web.controller.base;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseMainAirportContact;
import com.ruoyi.base.service.IBaseMainAirportContactService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主机场联络表;Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@Api(description="主机场联络表")
@RestController
@RequestMapping("/base/mainAirportContact")
public class BaseMainAirportContactController extends BaseController
{
    @Autowired
    private IBaseMainAirportContactService baseMainAirportContactService;

    /**
     * 查询主机场联络;列表
     */
    @ApiOperation("查询主机场联络")
    @GetMapping("/list")
    public TableDataInfo list(BaseMainAirportContact baseMainAirportContact)
    {
        startPage();
        baseMainAirportContact.setUnitCode(getLoginUser().getUser().getUnit());
        List<BaseMainAirportContact> list = baseMainAirportContactService.selectBaseMainAirportContactList(baseMainAirportContact);
        return getDataTable(list);
    }

    /**
     * 导出主机场联络;列表
     */
    @ApiOperation("导出主机场联络")
    @Log(title = "主机场联络表;", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseMainAirportContact baseMainAirportContact)
    {
        List<BaseMainAirportContact> list = baseMainAirportContactService.selectBaseMainAirportContactList(baseMainAirportContact);
        ExcelUtil<BaseMainAirportContact> util = new ExcelUtil<BaseMainAirportContact>(BaseMainAirportContact.class);
        util.exportExcel(response, list, "主机场联络表数据");
    }

    /**
     * 获取主机场联络;详细信息
     */
    @ApiOperation("获取主机场联络")
    @GetMapping(value = "/{ID}")
    public TableDataInfo getInfo(@PathVariable("ID") String ID)
    {
        List<BaseMainAirportContact> list =baseMainAirportContactService.selectBaseMainAirportContactByMaId(ID);
        return getDataTable(list);
    }

    /**
     * 新增主机场联络;
     */
    @ApiOperation("新增主机场联络")
    @Log(title = "主机场联络表;", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMainAirportContact baseMainAirportContact)
    {
        baseMainAirportContact.setID(UUID.randomUUID().toString().replace("-", ""));
        baseMainAirportContact.setCreatedBy(getUserId().toString());
        baseMainAirportContact.setCreatedTime(new Date());
        baseMainAirportContact.setUnitCode(getLoginUser().getUser().getUnit());
        return toAjax(baseMainAirportContactService.insertBaseMainAirportContact(baseMainAirportContact));
    }

    /**
     * 修改主机场联络;
     */
    @ApiOperation("修改主机场联络")
    @Log(title = "主机场联络表;", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMainAirportContact baseMainAirportContact)
    {
        baseMainAirportContact.setUpdatedBy(getUserId().toString());
        baseMainAirportContact.setUpdatedTime(new Date());
        return toAjax(baseMainAirportContactService.updateBaseMainAirportContact(baseMainAirportContact));
    }

    /**
     * 删除主机场联络;
     */
    @ApiOperation("删除主机场联络")
    @Log(title = "主机场联络表;", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(baseMainAirportContactService.deleteBaseMainAirportContactByIDs(IDs));
    }
}
